// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.randomizedWorld.randomizedBuilding;

import zombie.core.Rand;
import zombie.inventory.ItemPickerJava;
import zombie.iso.BuildingDef;
import zombie.iso.IsoCell;
import zombie.iso.IsoGridSquare;
import zombie.iso.IsoObject;
import zombie.iso.IsoWorld;
import zombie.iso.objects.IsoDoor;
import zombie.iso.objects.IsoWindow;

public final class RBLooted extends RandomizedBuildingBase {
    @Override
    public void randomizeBuilding(BuildingDef def) {
        def.bAlarmed = false;
        IsoCell isoCell = IsoWorld.instance.CurrentCell;

        for (int int0 = def.x - 1; int0 < def.x2 + 1; int0++) {
            for (int int1 = def.y - 1; int1 < def.y2 + 1; int1++) {
                for (int int2 = 0; int2 < 8; int2++) {
                    IsoGridSquare isoGridSquare = isoCell.getGridSquare(int0, int1, int2);
                    if (isoGridSquare != null) {
                        for (int int3 = 0; int3 < isoGridSquare.getObjects().size(); int3++) {
                            IsoObject isoObject = isoGridSquare.getObjects().get(int3);
                            if (Rand.Next(100) >= 85 && isoObject instanceof IsoDoor && ((IsoDoor)isoObject).isExteriorDoor(null)) {
                                ((IsoDoor)isoObject).destroy();
                            }

                            if (Rand.Next(100) >= 85 && isoObject instanceof IsoWindow) {
                                ((IsoWindow)isoObject).smashWindow(false, false);
                            }

                            if (isoObject.getContainer() != null && isoObject.getContainer().getItems() != null) {
                                for (int int4 = 0; int4 < isoObject.getContainer().getItems().size(); int4++) {
                                    if (Rand.Next(100) < 80) {
                                        isoObject.getContainer().getItems().remove(int4);
                                        int4--;
                                    }
                                }

                                ItemPickerJava.updateOverlaySprite(isoObject);
                                isoObject.getContainer().setExplored(true);
                            }
                        }
                    }
                }
            }
        }

        def.setAllExplored(true);
        def.bAlarmed = false;
    }

    public RBLooted() {
        this.name = "Looted";
        this.setChance(10);
    }
}
